package com.wksc.framework.impexp.pattern;

import com.wksc.framework.impexp.bean.BaseFormatParams;
import com.wksc.framework.impexp.util.ClassFactory;

/**
 * <p> Title(文件名): DecipherPattern.java </p>
 * <p> Description(描述): TODO </p>
 * <p> Copyright(版权): Copyright (c) 2011 </p>
 * <p> Company(公司): 成都四方信息技术有限公司 </p>
 * <p> CreateTime(生成日期)：2011-11-29下午04:15:16 </p>
 * @author wanglei
 * @version impExp_C13_P
 */
public class DecipherPattern implements FormatPattern,INeedRowContent {
	private static final long serialVersionUID = -1195331423258433654L;

	@Override
	public String format(BaseFormatParams params) {
		//获取当前行的数据
		Object[] dataLine = params.getLineContent();
		return decipherMsg(dataLine, params);
	}
	
	/***
	 * 
	 * <b>方法描述:</b>消息内容加密解密方法
	 *
	 * @company CDSF
	 * @createTime 2011-11-30
	 * @author nibo
	 * @param dataLine 当前行的数据
	 * @param params 格式化模板的参数对象
	 * @return 加/解密后的内容
	 */
	private String decipherMsg(Object[] dataLine, BaseFormatParams params) {
		String smType = null;
		String listType = null;
		String outLawDate = null;
		String deciphering = null;
		if (-1 != params.getSmTypeIndex() && null != dataLine[params.getSmTypeIndex()]) {
			smType = dataLine[params.getSmTypeIndex()].toString();
		}
		if (-1 != params.getListTypeIndex() && null != dataLine[params.getListTypeIndex()]) {
			listType = dataLine[params.getListTypeIndex()].toString();
		}
		if (-1 != params.getOutLawDateIndex() && null != dataLine[params.getOutLawDateIndex()]) {
			outLawDate = dataLine[params.getOutLawDateIndex()].toString();
		}
		if (null == dataLine[params.getDecipheringColIndex()]) {
			deciphering = "";
		} else {
			deciphering = dataLine[params.getDecipheringColIndex()].toString();
		}
		
		return ClassFactory.getData2FileDao().deciphering(
				deciphering, 
				smType,
				listType, 
				outLawDate,
				params.getMsgEncryptIsActive(), 
				params.getMsgClearIsActive(),
				params.getType());
	}

}
